package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author ht
 * @create 2025-06-19 21:20
 * @desc
 **/
public class T202 {

    public static boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        while (n != 1 && !set.contains(n)) {
            set.add(n);
            int res = 0;
            while (n > 0) {
                int num = n % 10;
                res += num * num;
                n = n / 10;
            }
            n = res;
        }
        return n == 1;
    }

    public static void main(String[] args) {
        System.out.println(isHappy(19));
    }
}
